home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / BSDSoundLib 1.0.3 / examples / AsyncSound Player ƒ / AsyncSound Player.c next >
Encoding:
C/C++ Source or Header  |  1997-08-03  |  2.4 KB  |  109 lines  |  [TEXT/CWIE]

  1. #include <BSDSoundLib.h>
  2.  
  3. Handle                snd;
  4. Boolean                done = false;
  5. CursHandle            left, center, right;
  6. short                refNum, oldResFile;
  7. StandardFileReply    file;
  8.  
  9. void main (void);
  10. Boolean IsKeyPressed (unsigned short keycode);
  11. Boolean OpenSndFile (StandardFileReply *reply, short *refNum);
  12.  
  13. Boolean IsKeyPressed (unsigned short keycode) {
  14. unsigned char km[16];
  15.  
  16.     GetKeys((unsigned long*)km);
  17.     return ((km[keycode >> 3] >> (keycode & 7)) & 1);
  18. }
  19.  
  20. Boolean OpenSndFile (StandardFileReply *reply, short *refNum) {
  21. SFTypeList    typeList;
  22.  
  23.     typeList[0] = 'sfil';
  24.     StandardGetFile(nil, 1, typeList, reply);
  25.     if (reply->sfGood) {
  26.         (*refNum) = FSpOpenResFile(&reply->sfFile, fsRdPerm);
  27.         return(true);
  28.     }
  29.     return(false);
  30. }
  31.  
  32. void main (void) {
  33. Str255    s;
  34. short    freeChan = 0;
  35. Point    mouse;
  36.  
  37.     MaxApplZone();
  38.     
  39.     InitGraf(&qd.thePort);
  40.     InitDialogs(nil);
  41.     InitFonts();
  42.     InitWindows();
  43.     
  44.     FlushEvents(everyEvent, 0);
  45.     
  46.     HLockHi((Handle)(left = GetCursor(128)));
  47.     HLockHi((Handle)(center = GetCursor(129)));
  48.     HLockHi((Handle)(right = GetCursor(130)));
  49.     
  50.     InitSoundUtils(kMaxSndChans);    //Initialize sound channels
  51.     
  52.     NumToString(numChannels, s);
  53.     ParamText(s, nil, nil ,nil);
  54.     Alert(128, nil);
  55.     ParamText(nil, nil, nil, nil);
  56.     
  57.     oldResFile = CurResFile();
  58.     if (!OpenSndFile(&file, &refNum)) ExitToShell();
  59.     
  60.     snd = GetIndResource('snd ', 1);
  61.     HLockHi(snd);
  62.     DetachResource(snd);
  63.     
  64.     CloseResFile(refNum);
  65.     UseResFile(oldResFile);
  66.     
  67.     while (!done) {
  68.     
  69.         GetMouse(&mouse);
  70.         if (mouse.h < 213) SetCursor((*left));
  71.         else if (mouse.h > 426) SetCursor((*right));
  72.         else SetCursor((*center));
  73.         
  74.         if (Button()) {
  75.             freeChan = FindFreeChannel();
  76.             if (freeChan != -1) {
  77.             
  78.                 if (mouse.h < 213) SetChanVol(freeChan, kMaxLeft);
  79.                 else if (mouse.h > 426) SetChanVol(freeChan, kMaxRight);
  80.                 else SetChanVol(freeChan, kBalanced);
  81.                 
  82.                 PlaySoundChan(freeChan, snd);        // play sound on a free channel
  83.                 if (Button()) Delay(15, nil);
  84.             }
  85.         }
  86.         
  87.         if    ((IsKeyPressed(12) && IsKeyPressed(55)) || 
  88.             (IsKeyPressed(53))) done = true;
  89.     }
  90.     
  91.     DisposeSoundUtils();        // dispose sound channels
  92.     
  93.     HUnlock(snd);
  94.     DisposeHandle(snd);
  95.     
  96.     HUnlock((Handle)left);
  97.     ReleaseResource((Handle)left);
  98.     DisposeHandle((Handle)left);
  99.     HUnlock((Handle)center);
  100.     DisposeHandle((Handle)center);
  101.     ReleaseResource((Handle)center);
  102.     HUnlock((Handle)right);
  103.     DisposeHandle((Handle)right);
  104.     ReleaseResource((Handle)right);
  105.     
  106.     InitCursor();
  107.     
  108.     FlushEvents(everyEvent, 0);
  109. }